//
//  HPCarouselColleVCell.m
//  彩虹儿歌
//
//  Created by HelloWorld_L on 15/7/1.
//  Copyright (c) 2015年 HelloBaby. All rights reserved.
//

#import "HPCarouselColleVCell.h"
#import "MacroHeader.h"
#import <UIImageView+WebCache.h>

@implementation HPCarouselColleVCell

- (void)dealloc
{
    [_backGroundImgV release];
    [_carouselCScrollV release];
    [_pageControl release];
    [_imageV1 release];
    [_imageV2 release];
    [_imageV3 release];
    [_imageV4 release];
    [_imageV5 release];
    [_imageV6 release];
    [_imageVsArr release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backGroundImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 4)];
        self.backGroundImgV.image = [UIImage imageNamed:@"188933-12052GH94711.jpg"];
        self.backGroundImgV.layer.cornerRadius = 40;
        self.backGroundImgV.layer.masksToBounds = YES;
        self.backGroundImgV.userInteractionEnabled = YES;
        
        self.carouselCScrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 4)];
        self.carouselCScrollV.backgroundColor = [UIColor clearColor];
        
        self.carouselCScrollV.layer.shadowColor = [[UIColor blackColor] CGColor];
        self.carouselCScrollV.layer.shadowOffset = CGSizeMake(0, 0);
        self.carouselCScrollV.layer.shadowRadius = 20;
        self.carouselCScrollV.layer.shadowOpacity = 3;
        
        
        self.carouselCScrollV.contentSize = CGSizeMake(5 * SCREEN_WIDTH, SCREEN_HEIGHT / 4);
        self.carouselCScrollV.pagingEnabled = YES;
        self.carouselCScrollV.bounces = NO;
        self.carouselCScrollV.showsHorizontalScrollIndicator = NO;//隐藏滚动条。
        
        self.pageControl = [[StyledPageControl alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT / 4 - 20, SCREEN_WIDTH, 20)];
        self.pageControl.pageControlStyle = PageControlStyleWithPageNumber;
        self.pageControl.backgroundColor = [UIColor clearColor];
        self.pageControl.numberOfPages = 5;

        
        
        self.imageVsArr = [NSMutableArray array];
        
        self.imageV1 = [[UIImageView alloc] init];
        [self.imageVsArr addObject:self.imageV1];
        self.imageV2 = [[UIImageView alloc] init];
        [self.imageVsArr addObject:self.imageV2];
        self.imageV3 = [[UIImageView alloc] init];
        [self.imageVsArr addObject:self.imageV3];
        self.imageV4 = [[UIImageView alloc] init];
        [self.imageVsArr addObject:self.imageV4];
        self.imageV5 = [[UIImageView alloc] init];
        [self.imageVsArr addObject:self.imageV5];
        self.imageV6 = [[UIImageView alloc] init];
        [self.imageVsArr addObject:self.imageV6];
        
        
        [self.backGroundImgV addSubview:self.carouselCScrollV];
        [self.backGroundImgV addSubview:self.pageControl];
        [self.contentView addSubview:self.backGroundImgV];
        
        [self.carouselCScrollV release];
        [self.pageControl release];
        [self.backGroundImgV release];
        [self.imageV1 release];
        [self.imageV2 release];
        [self.imageV3 release];
        [self.imageV4 release];
        [self.imageV5 release];
        [self.imageV6 release];
        
    }
    return self;
}

- (void)setcarcouselWithArr:(NSMutableArray *)arr
{
    
    for (int i = 0; i < arr.count; i++) {

        UIImageView *imageV = (UIImageView *)self.imageVsArr[i];
        NSString *str =  [(HPVCModel *)arr[i] recommend_pic];

        str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];// NSURL初始化失败时解决办法是将字符串网址进行一次NSUTF8转码再使用。
        
        [imageV sd_setImageWithURL:[NSURL URLWithString:str]];

        imageV.frame = CGRectMake( i * SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 4);
        
        [self.carouselCScrollV addSubview:imageV];

    }

}

@end
